<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    //封装一个函数toMoneyStr.传入不定长度的表示金额的字符串，转换为千位分割效果，返回转换后的字符串；
    //如：toMoneyStr（“1234567”）得到"1,234,567"
    function toMoneyStr(str) {
        return str.toLocaleString(str)
    }
    var str = 1234567
    console.log(toMoneyStr(str));
</script>